cmake_minimum_required(VERSION 2.6)
project(DummyProject)

#I set the executable and library name both from the project name. All libraries will have l_ prefix

set(EXECUTABLE_NAME     ${PROJECT_NAME})
set(LIBRARY_NAME        l_${PROJECT_NAME})

#use this variable to add libraries at compilation, such as set(LIB_FILE sfml-main sfml-window) etc

set(LIB_FILES)

#The SRC_FILES and INCLUDE_FILES variable are here to gather every sources and header files

set(SRC_FILES 		${CMAKE_CURRENT_SOURCE_DIR}/src/dummy.cpp)
set(INCLUDE_FILES 	${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/dummy.h)

option(BUILD_LIB            "Determine if a lib must be build from the project or not"  ON)
option(BUILD_SHARED_LIBS    "Determine if the lib must be shared or static"             ON)

#Here I define the path where the lib and the executable must be build

set(EXECUTABLE_OUTPUT_PATH  ${CMAKE_CURRENT_SOURCE_DIR}/bin/)
set(LIBRARY_OUTPUT_PATH     ${CMAKE_CURRENT_SOURCE_DIR}/bin/)

# This little test is used to determine how the lib must be build : shared or static

if(BUILD_SHARED_LIBS)
    set(BUILD_LIB_OPTION SHARED)
else(BUILD_SHARED_LIBS)
    set(BUILD_LIB_OPTION STATIC)
endif(BUILD_SHARED_LIBS)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include /
${CMAKE_CURRENT_SOURCE_DIR}/../../include
)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../lib)

if(BUILD_LIB)

    add_library(
            ${LIBRARY_NAME}
            ${BUILD_LIB_OPTION}
            ${SRC_FILES}
    )

    target_link_libraries(
        ${LIBRARY_NAME}
        ${LIB_FILES}
    )
endif(BUILD_LIB)




if(BUILD_LIB)

	add_executable(
		${EXECUTABLE_NAME}
		main.cpp
                ${INCLUDE_FILES}
	)

    target_link_libraries(
        ${EXECUTABLE_NAME}
        ${LIBRARY_NAME}
    )

else(BUILD_LIB)

	add_executable(
		${EXECUTABLE_NAME}
		${SRC_FILES}
		main.cpp
		${INCLUDE_FILES}
	)
    target_link_libraries(
        ${EXECUTABLE_NAME}
        ${LIB_FILES}
    )

endif(BUILD_LIB)

if(BUILD_LIB)

    #Here, we use the cmake command "Install" to move the selected files to another directory
    #Here, we take all the header and send them in my "general" include director
    #CMAKE_CURRENT_SOURCE_DIR is the directory where the CMakeLists.txt is located
    INSTALL(FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../include/${PROJECT_NAME}/)
    #Same thing, but with targets instead of files. Targets can be executable or library
    INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/)

endif(BUILD_LIB)
